﻿using Microsoft.Extensions.DependencyInjection;
using System;

namespace HzyScanDiService.Extensions
{
    /// <summary>
    /// 服务提供者扩展
    /// </summary>
    public static class ServiceProviderExtensions
    {
        private static IServiceProvider _serviceProvider;

        static ServiceProviderExtensions() { }

        /// <summary>
        /// 注册 服务提供者
        /// </summary>
        /// <param name="serviceProvider"></param>
        public static void UseServiceProvider(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        /// <summary>
        /// 获取服务提供者
        /// </summary>
        /// <returns></returns>
        public static IServiceProvider GetServiceProvider() => _serviceProvider;

        /// <summary>
        /// 创建服务域
        /// </summary>
        /// <returns></returns>
        public static IServiceScope CreateScope() => _serviceProvider.CreateScope();

    }

}
